import util from "@/commons/js/util.js";
  /* 乐怡社区版入院办理 */
  //老人姓名
  var validateoldName = (rule, value, callback) => {
    if (!value) {
      callback(new Error("老人姓名不能为空"));
    } else {
      callback();
    }
  };
  //老人身份证
  var validateOldId = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入老人身份证号"));
    } else {
      //by guo 2019-3-28    添加15 和18位的身份证验证年月日合法
      var re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
      //also re = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
      var arrSplit = value.match(re); //检查生日日期是否正确  18位
      var re2 = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
      var arrSplit2 = value.match(re2); //检查生日日期是否正确  15位
      if (arrSplit != null) {
        var check18 = util.formatDate.YearMonthDayValidate(
          arrSplit[2],
          arrSplit[3],
          arrSplit[4]
        );
        console.log(check18);
      }
      if (arrSplit2 != null) {
        if (parseInt(arrSplit2[2].substr(1)) > 0) {
          arrSplit2[2] = "19" + arrSplit2[2];
        } else {
          arrSplit2[2] = "20" + arrSplit2[2];
        }
        var check15 = util.formatDate.YearMonthDayValidate(
          arrSplit2[2],
          arrSplit2[3],
          arrSplit2[4]
        );
        console.log(check15);
      }

      //  老身份证15位  新身份证18位(最后一位可以使大写X)
      //var reg = /^(\d{15}|\d{17}[xX\d])$/
      var reg = /^(\d{15}|\d{17}[X\d])$/;//by guo 2019-11-04-17:14修改
      if (!reg.test(value)) {
        callback(new Error("请输入正确的身份证号码"));
      } else if (check18 == false || check15 == false) {
        //by guo 2019-3-28 添加
        callback(new Error("出生日期不准确"));
      } else {
        callback();
      }
    }
  };
  //紧急联系人身份证
  var validateEgaIdCard = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入老人身份证号"));
    } else {
      //by guo 2019-3-28    添加15 和18位的身份证验证年月日合法
      var re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
      //also re = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
      var arrSplit = value.match(re); //检查生日日期是否正确  18位
      var re2 = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
      var arrSplit2 = value.match(re2); //检查生日日期是否正确  15位
      if (arrSplit != null) {
        var check18 = util.formatDate.YearMonthDayValidate(
          arrSplit[2],
          arrSplit[3],
          arrSplit[4]
        );
        console.log(check18);
      }
      if (arrSplit2 != null) {
        if (parseInt(arrSplit2[2].substr(1)) > 0) {
          arrSplit2[2] = "19" + arrSplit2[2];
        } else {
          arrSplit2[2] = "20" + arrSplit2[2];
        }
        var check15 = util.formatDate.YearMonthDayValidate(
          arrSplit2[2],
          arrSplit2[3],
          arrSplit2[4]
        );
        console.log(check15);
      }

      //  老身份证15位  新身份证18位(最后一位可以使大写X)
      //var reg = /^(\d{15}|\d{17}[xX\d])$/
      var reg = /^(\d{15}|\d{17}[X\d])$/;//by guo 2019-11-04-17:14修改
      if (!reg.test(value)) {
        callback(new Error("请输入正确的身份证号码"));
      } else if (check18 == false || check15 == false) {
        //by guo 2019-3-28 添加
        callback(new Error("出生日期不准确"));
      } else {
        callback();
      }
    }
  };
  //电话号码
  var validatePhone = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入手机号"));
    } else {
      //  因为现在新增了166、198、199号段的手机号
      var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
      if (!reg.test(value)) {
        callback(new Error("手机号码格式错误"));
      } else {
        callback();
      }
    }
  };
  //家属电话号码a
  var validateEgPhonea = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入紧急联系人电话"));
    } else {
      //  因为现在新增了166、198、199号段的手机号
      var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
      if (!reg.test(value)) {
        callback(new Error("手机号码格式错误"));
      } else {
        callback();
      }
    }
  };
  //家属电话号码b
  var validateEgPhoneb = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入联系人电话"));
    } else {
      //  因为现在新增了166、198、199号段的手机号
      var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
      if (!reg.test(value)) {
        callback(new Error("手机号码格式错误"));
      } else {
        callback();
      }
    }
  };
  //紧急联系人电话
  var validateHomePhoneb = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入紧急联系人电话"));
    } else {
      //  因为现在新增了166、198、199号段的手机号
      var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
      if (!reg.test(value)) {
        callback(new Error("手机号码格式错误"));
      } else {
        callback();
      }
    }
  };
  //紧急联系人a
  var validategNamea = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入紧急联系人姓名"));
    } else {
      callback();
    }
  };
  //紧急联系人b
  var validategNameb = (rule, value, callback) => {
    if (!value) {
      return callback(new Error("请输入家属姓名"));
    } else {
      callback();
    }
  };
  //月收入
  var validategOldMonIncome = (rule, value, callback) => {
    console.log(value);
    if(!String(value)){
      return callback(new Error("请选择月收入"));
    } else{
      callback();
    }
  };

  //费用
  var validateFee = (rule, value, callback) => {
    console.log(value);
    var reg = /(^[0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/g; //大于等于0的数，最多可以有两位小数正则表达式
    if(reg.test(value)){
      if(value>9999999.99){
        return callback(new Error("最大金额不能查过9999999.99"));
      }else {
        callback();
      }
    } else{
      callback(new Error("请输入不小于0并最多只能有两位小数的金额"));
    }
  };

  //老人入院办理
  //by guo 2019-11-26-11:46添加 校验老人姓名不能输入特殊字符
  var validateInput = (rule, value, callback) => {
    console.log(value,util.formatDate.checkSpecialKey(value));
    if (!util.formatDate.checkSpecialKey(value)) {
      callback(new Error("老人姓名不能含有特殊字符"));
    } else {
      callback();
    }
  }

  //娱乐管理 上传音乐 的输入框的回显
  var validateMusic = (rule, value, callback) => {
    console.log(value,"----------");
    if (value=="" || value==undefined || value==null) {
      callback(new Error("请上传音乐"));
    } else {
      callback();
    }
  }

    //娱乐管理 上传视频的输入框的回显
    var validateVideo = (rule, value, callback) => {
      console.log(value,util.formatDate.checkSpecialKey(value));
      if (value=="" || value==undefined || value==null) {
        callback(new Error("请上传视频"));
      } else {
        callback();
      }
    }

  //娱乐管理 上传语音的输入框的回显
  var validateVoice = (rule, value, callback) => {
    console.log(value,util.formatDate.checkSpecialKey(value));
    if (value=="" || value==undefined || value==null) {
      callback(new Error("请上传语音"));
    } else {
      callback();
    }
  }

  //导出变量
  export{
    validateoldName,
    validateOldId,
    validateEgaIdCard,
    validatePhone,
    validateEgPhonea,
    validateEgPhoneb,
    validateHomePhoneb,
    validategNamea,
    validategNameb,
    validategOldMonIncome,
    validateFee,
    validateInput,
    validateMusic,
    validateVideo,
    validateVoice,
  }